
package nc.impl.uapbd.material_sa.material_sa;

import java.util.Arrays;

import org.apache.commons.lang3.ArrayUtils;

import nc.bs.framework.common.NCLocator;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.SuperVO;
import nc.vo.pub.ISuperVO;
import nc.vo.pub.IVOMeta;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.model.meta.entity.bill.IBillMeta;
import nc.vo.trade.pub.HYBillVO;
import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nccloud.bs.excel.IXChangeContext;
import nccloud.bs.excel.plugin.AbstractImportProceeWithContext;
import nc.vo.uapbd.material.MaterialSaBVO;
import nc.vo.uapbd.material.MaterialSaVO;
import nc.vo.uapbd.material.AggMaterialSaVO;
import nc.itf.uapbd.material_sa.material_sa.IMaterialSaVOService;

public class AggMaterialSaVOImportProcess extends AbstractImportProceeWithContext {
	
	@Override
	protected void processBillWithContext(Object vo, IXChangeContext changcontext) throws BusinessException {
		AggMaterialSaVO targetVO = (AggMaterialSaVO)vo;
		targetVO.getParentVO().setStatus(VOStatus.NEW);

		MaterialSaBVO[] materialSaBVOs = (MaterialSaBVO[])targetVO.getChildren(MaterialSaBVO.class);
		if(materialSaBVOs!=null && materialSaBVOs.length>0){
			Arrays.stream(materialSaBVOs).forEach(subvo->{
				subvo.setStatus(VOStatus.NEW);
			});
		}
  		getService().initDefaultData(targetVO.getParentVO());
		getService().saveAggMaterialSaVO(targetVO);
	}
	
	private IMaterialSaVOService getService() {
		return NCLocator.getInstance().lookup(IMaterialSaVOService.class);
	}

}
